<?php
	session_start();
	$UserID = trim($_SESSION['user_id']);
	
	header('Content-type: application/json');
	$url = "";
	require_once 'application/dataAccess.php';
	$da = new dataAccess();
	$term = $_GET["term"];
	$content = "";	
	$found = false;
	$year = "";
	$uploader = "";
	if (strlen($term) > 0)
	{
		$result = $da->searchPdfTerms($term, $UserID);
		echo mysql_error();	
		while($row = mysql_fetch_array($result))
		{									
			$url .= $row["url"];
			$content = $row["content"];
			$year = $row["year"];
			$uploader = $row["firstname"];
			$found = true;
			break;			
		}
		$url = trim($url, ",");
	}
	$obj = array("term" => $term, "url" => $url, "content" => $content, "found" => $found, "year" => $year, "uploader" => $uploader);
	//$data = '{"term": "'. $term .'", "urls":['. $url .'],"content": "'. $content .'" }';	
	//echo json_encode($data);
	echo json_encode($obj);
?>